<template>
  <div>
    <!-- 面包导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/admin' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>管理员管理</el-breadcrumb-item>
      <el-breadcrumb-item>管理员列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card style="margin-left:-1rem;margin-top:1rem">
  

      <!-- 用户列表区域 -->
      <el-form ref="loginFormRef" :rules="Loginrules" label-width="80px" :model="loginForm">
        <el-form-item  prop="name" label="用户名">
          <el-input v-model="loginForm.name"></el-input>
        </el-form-item>
        <el-form-item prop="password" label="密码">
          <el-input v-model="loginForm.password"></el-input>
        </el-form-item>
         <el-form-item class="btns">
              <el-button type="primary" @click="addupdate()">更新</el-button>
         </el-form-item>
      </el-form>


    </el-card>
  </div>
</template>    

<script>
import { setToken, setUserName } from "../../utils/auth";
import request from "../../utils/request";
export default {
  data(){
    return{
      id:"",
        //添加用户的表单数据
        loginForm:{   
            name:'',
            password:''
        },
             //表单的验证规则对象
         Loginrules :{
             //验证用户名是否合法
             name:[
                { required: true, message: '请输入用户名', trigger: 'blur' },
                { min: 3, max: 5, message: '用户名长度在 3 到 5 个字符', trigger: 'blur' }
             ],
              // 验证密码是否合法
              password:[
                { required: true, message: '请输入密码', trigger: 'blur' },
                { min: 3, max: 8, message: '密码长度在 3 到 8 个字符', trigger: 'blur' }
              ]
         }
    }
  },
  created() {
    this.getUserList()
  },
  methods: {
     getUserList() {
    let id = this.$route.query.id;
    this.id = id
      var that = this
     request({
        url: "/api/user/getAdminupdateList",
        method: "post",
        data: {id}
      }).then(res => {
        console.log(res)
       that.loginForm.name = res.list[0].name;
       that.loginForm.password = res.list[0].password;
      });
    },
     //添加管理员
    addupdate() {
      const params = {
       id:this.id,
       name:this.loginForm.name,
       password:this.loginForm.password
      
     }
     console.log(params)
      request({
        url: "/api/user/addadminupdate",
        method: "post",
        data: params
      }).then(res => {
        if (res.msg === "新增成功") {
          this.$message({
            message: "恭喜你，新增成功",
            type: "success"
          });
          this.$router.push("/admin/welcome");
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>


